﻿module Sustainalytics.GCCS {

    export class GCAssessmentSummaryAndConclusionsController {

        // principle summary ID
        private principleSummaryId: string;

        // company - principle controller
        private companyPrincipleController: GCCompanyPrincipleController;

        // principle - conclusion
        private principleConclusion: GCPrincipleConclusionDto;

        // principle - event indicators
        private principleEventIndicators: GCPrincipleEventIndicatorDto[];


        constructor(
            public $scope: ng.IScope,
            private $q: ng.IQService,
            private GCPrincipleEventIndicatorService: IGCPrincipleEventIndicatorService,
            private GCPrincipleConclusionService: IGCPrincipleConclusionService) {

            var ctx = this;
            $scope['gcAssessmentSummaryAndConclusions'] = ctx;

            // get principle controller
            ctx.companyPrincipleController = $scope['gcCompanyPrinciple'];

            // current principle summary ID
            ctx.principleSummaryId = ctx.companyPrincipleController.companyPrinciple.id;

            ctx.getPrincipleConclusionInfo();
            ctx.getPrincipleEventIndicators();
        }

        // get principle conclusion
        public getPrincipleConclusionInfo(): ng.IPromise<GCPrincipleConclusionDto> {
            var ctx = this;

            var promise = ctx.GCPrincipleConclusionService.GetByPrincipleSummaryId(ctx.principleSummaryId);

            promise.then(function (data) {
                ctx.principleConclusion = data;
            });

            return promise;
        }

        // get all principle event indicators
        public getPrincipleEventIndicators(): ng.IPromise<GCPrincipleEventIndicatorDto[]> {
            var ctx = this;

            var promise = ctx.GCPrincipleEventIndicatorService.GetByPrincipleSummaryId(ctx.principleSummaryId);

            promise.then(function (data) {
                ctx.principleEventIndicators = data;
            });

            return promise;
        }
    }


    angular.module('Sustainalytics.GCCS').controller('GCAssessmentSummaryAndConclusionsController',
        ['$scope', '$q', 'GCPrincipleEventIndicatorService', 'GCPrincipleConclusionService', GCAssessmentSummaryAndConclusionsController]);
} 